package com.grgbanking.it.wx.common.creator;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.grgbanking.it.common.HttpConnection;
import com.grgbanking.it.wx.common.Token;
import com.grgbanking.it.wx.common.WXConstant;

/**
 * 微信菜单创建
 * 
 * WXMenuCreator
 * 
 * @author 潘广伟
 * @Email p_3er@qq.com
 * @Date 2014-11-5 下午2:43:01
 * 
 * @version 1.0.0
 *
 */
@Component
public class WXMenuCreator {
	@Autowired
	private HttpConnection httpConnection;

	/**
	 * 创建应用菜单
	 * create
	 * 
	 * @param agentId
	 * @param json
	 * @return
	 * @throws Exception 
	 * @exception 
	 * @since  1.0.0
	 */
	public String create(Integer agentId,String json) throws Exception{
		String url = createURL(WXConstant.MENU_CREAT_URL, agentId);
		String callback = httpConnection.sendPost(url.toString(), json);
		return callback;
	}
	/**
	 * 删除应用菜单
	 * delete
	 * 
	 * @param agentId
	 * @return
	 * @throws Exception 
	 * @exception 
	 * @since  1.0.0
	 */
	public String delete(Integer agentId) throws Exception{
		String url = createURL(WXConstant.MENU_DELETE_URL, agentId);
		String callback = httpConnection.sendGet(url.toString());
		return callback;
	}
	
	public String createURL(String menuURL,Integer agentId) throws Exception{
		StringBuffer url = new StringBuffer(menuURL);
		url.append("?access_token=").append(Token.getToken(httpConnection));
		url.append("&agentid=").append(agentId);
		
		return url.toString();
	}
}
